#@layout()
#define head()
<script>
$(function(){
	var h = $(window).height();
	$("#contain").css("height",h-130+"px");
});

function addCart(goodsId,countEle){
	var num = $("#"+countEle).val();
	var n = parseInt(num);
	console.log(goodsId + "  " + n);
	$.post("#(CONTEXT_PATH??)/m/addCard",{goodsId:goodsId,cnt:n},function(data){
		if(data=="suc"){
			$.toast("添加到购物车成功！", "text");
		}
	});
}
</script>
#end

#define content()
	<div style="width:100%;height:30px;line-height: 30px;display: flex;margin-top:10px;">
		分类
   	  	<select id="category" style="width:70%;height:40px;">
   	  		<option value="">请选择</option>
   	  		#for(gc : gcs)
   	  		<option value="#(gc.id??)">#(gc.name??)</option>
   	  		#end
   	  	</select>
	</div>
	
  	<div  id="contain" class="weui-cells" style="overflow-y:auto" >
		#for(row : goods)
   	  	<div style="margin:20px;height: 50px;border-bottom:1px solid #f3f3f3;">
   	  	<div style="width:40px;height:40px;display: inline-block;">
   	  		<img src="#(CONTEXT_PATH??)/upload/temp/#(row.img??)" style="max-height: 40px;max-width:40px;" />
   	  	</div>
   	  	<div style="display: inline-block;">
   	  		<storng>#(row.name??)</storng><br>
   	  		<span>#(row.price??)元</span>
   	  	</div>
   	  	 
   	  	
   	  	<div class="weui-count" style="magin-left:20px;">
          <a class="weui-count__btn weui-count__decrease"></a>
          <input id="n#(row.id??)" class="weui-count__number" type="number" value="1" />
          <a class="weui-count__btn weui-count__increase"></a>
        </div>
   	  	<a href="javascript:addCart(#(row.id??),'n#(row.id??)');" class="weui-btn weui-btn_mini weui-btn_primary" style="position: absolute;right:10px;">加入购物车</a>
   	  	</div>
   	  	#end
	</div>
	
	<script>
	var MAX = 99, MIN = 1;
	$('.weui-count__decrease').click(function (e) {
	  var $input = $(e.currentTarget).parent().find('.weui-count__number');
	  var number = parseInt($input.val() || "0") - 1
	  if (number < MIN) number = MIN;
	  $input.val(number)
	})
	$('.weui-count__increase').click(function (e) {
	  var $input = $(e.currentTarget).parent().find('.weui-count__number');
	  var number = parseInt($input.val() || "0") + 1
	  if (number > MAX) number = MAX;
	  $input.val(number)
	})
	</script>
#end
